package fileexplorer;

import fileexplorer.controller.FileExplorerController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.File;
import java.io.IOException;

public class FileExplorer extends Application {
    private String filePath;
    private File file;
    private FileExplorerController fileExplorerController;
    private Stage stage;

    public FileExplorer(){
        filePath = getLastDirectory();
        file = new File(filePath);
    }

    @Override
    public void start(Stage primaryStage){
        //show the ui pane
        stage = primaryStage;
        stage.initStyle(StageStyle.TRANSPARENT);
        try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource("/fxml/FileExplorer.fxml"));
            Parent root = loader.load();
            fileExplorerController = loader.getController();
            fileExplorerController.init(this);
            TreeItem treeItem = fileExplorerController.initFileNode();
            ((TreeView)root.lookup("#tree")).setRoot(treeItem);
            Scene scene = new Scene(root, 944,627);
            stage.setScene(scene);
            stage.setResizable(false);
            stage.setAlwaysOnTop(true);
            stage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    private String getLastDirectory(){
        //返回上次访问过得目录
        return "";
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public Stage getStage() {
        return stage;
    }

    public void setStage(Stage stage) {
        this.stage = stage;
    }

    public static void main(String[] args){
        launch(args);
    }

    public void close(){
        stage.close();
    }
}
